
package com.ami.kvm.jviewer.gui;

import com.ami.kvm.jviewer.Debug;
import com.ami.kvm.jviewer.JViewer;
import com.ami.kvm.jviewer.common.oem.IOEMAuthentication;
import com.ami.kvm.jviewer.common.oem.IOEMManager;
import com.ami.kvm.jviewer.common.oem.IOEMStandAloneConnectionDialog;
import com.ami.kvm.jviewer.videorecord.URLProcessor;
import com.ami.kvm.jviewer.videorecord.VideoRecordApp;
import com.ami.vmedia.VMApp;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Container;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.awt.Rectangle;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.FocusAdapter;
import java.awt.event.FocusEvent;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.Socket;
import java.net.URL;
import java.security.CodeSource;
import java.security.ProtectionDomain;
import java.util.Locale;
import javax.swing.BorderFactory;
import javax.swing.ButtonGroup;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
import javax.swing.JProgressBar;
import javax.swing.JRadioButton;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.JTextField;
import javax.swing.border.Border;
import javax.swing.border.TitledBorder;
import javax.swing.table.AbstractTableModel;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.JTableHeader;
import javax.swing.table.TableModel;

public class StandAloneConnectionDialog extends JDialog implements ActionListener, ItemListener {
	private final int WIDTH = 410;
	private final int HEIGHT = 280;
	private final int SECURE_CONNECT = 1;
	private final int HTTPS_CONNECTION_SUCCESS = 0;
	private final int ADMIN_USER = 4;
	private final int OEM_PROPRIETARY_USER = 5;

	private final int KVM_VMEDIA = 0;
	private final int VMEDIA_APP = 1;
	private final int MANAGE_VIDEO = 2;

	private String hostIP = null;
	private String username = null;
	private String password = null;
	private String webSessionToken = null;
	private String csrfToken = null;
	private static String selectedLocale = "EN";
	private int secWebPort = 443;

	private JPanel textPanel;

	private JPanel btnPanel;
	private JPanel helpPanel;
	private JPanel progressPanel;
	private JPanel bottomPanel;
	private JTable videoTable;
	private JLabel ipLabel;
	private JLabel portLabel;
	private JLabel unameLabel;
	private JLabel passwdLabel;
	private JLabel localeLabel;
	private JLabel appTypeLabel;
	private JTextField ipText;
	private JTextField portText;
	private JTextField unameText;
	private JPasswordField passwdText;
	private JButton launchBtn;
	private JButton cancelBtn;
	private JComboBox localeList;
	private JComboBox appTypeList;
	private JLabel helpTextLabel;
	private DefaultTableModel model;
	private JRadioButton playVideoRBtn;
	private JRadioButton saveVideoRBtn;
	private ButtonGroup videoOption;
	private JProgressBar launchProgressBar;
	private URLProcessor urlProcessor;
	private Validator validator;
	private DialogKeyListener keyListener;
	private DialogWindowListener windowListener;
	private TextFieldFocusListener textFieldFocusListener;
	private boolean validate = true;

	private boolean firstCheck = true;
	private boolean webLogIn = false;
	private boolean buttonsEnabled = false;
	private String[][] videoFile;
	private int remotePathSupport = 0;
	private int appType = 0;

	public StandAloneConnectionDialog(JFrame paramJFrame, String paramString1, int paramInt, String paramString2,
			String paramString3) {
		super(paramJFrame, LocaleStrings.getString("S_1_SACD") + JViewer.getTitle(), false);

		this.username = paramString2;
		this.password = paramString3;
		this.hostIP = paramString1;
		this.secWebPort = paramInt;
		selectedLocale = JViewer.getLanguage();
		this.windowListener = new DialogWindowListener();
		addWindowListener(this.windowListener);
		constructDialog();
		enableDialog();

		if ((JViewer.getArgLength() > 0) && (!JViewer.isUnknownArgs())
				&& (JViewer.isStandAloneSupportedApps(JViewer.getLaunch()))) {

			showDialog();
		}
	}

	private void constructDialog() {
		Dimension localDimension = Toolkit.getDefaultToolkit().getScreenSize();
		this.keyListener = new DialogKeyListener();
		this.textFieldFocusListener = new TextFieldFocusListener();
		setBounds(new Rectangle((localDimension.width - 410) / 2, (localDimension.height - 280) / 2, 410, 280));
		setLayout(new BorderLayout());
		setResizable(false);
		this.textPanel = new JPanel();

		this.textPanel.setLayout(new GridBagLayout());
		GridBagConstraints localGridBagConstraints = new GridBagConstraints();

		localGridBagConstraints.fill = 2;
		localGridBagConstraints.insets = new Insets(10, 10, 5, 10);
		localGridBagConstraints.gridx = 0;
		localGridBagConstraints.gridy = 0;
		localGridBagConstraints.gridwidth = 1;
		localGridBagConstraints.gridheight = 1;
		localGridBagConstraints.weightx = 0.0D;

		this.ipLabel = new JLabel(LocaleStrings.getString("S_2_SACD") + " : ");
		this.textPanel.add(this.ipLabel, localGridBagConstraints);

		localGridBagConstraints.insets = new Insets(5, 10, 5, 10);
		localGridBagConstraints.gridy = 1;

		this.portLabel = new JLabel(LocaleStrings.getString("S_3_SACD") + " : ");
		this.textPanel.add(this.portLabel, localGridBagConstraints);

		localGridBagConstraints.gridy = 2;

		this.unameLabel = new JLabel(LocaleStrings.getString("S_4_SACD") + " : ");
		this.textPanel.add(this.unameLabel, localGridBagConstraints);

		localGridBagConstraints.gridy = 3;

		this.passwdLabel = new JLabel(LocaleStrings.getString("S_5_SACD") + " : ");
		this.textPanel.add(this.passwdLabel, localGridBagConstraints);

		localGridBagConstraints.gridy = 4;

		this.localeLabel = new JLabel(LocaleStrings.getString("S_21_SACD") + " : ");
		this.textPanel.add(this.localeLabel, localGridBagConstraints);

		localGridBagConstraints.gridy = 5;

		this.appTypeLabel = new JLabel(LocaleStrings.getString("S_34_SACD") + " : ");
		this.textPanel.add(this.appTypeLabel, localGridBagConstraints);

		localGridBagConstraints.insets = new Insets(10, 10, 5, 10);
		localGridBagConstraints.fill = 2;
		localGridBagConstraints.gridx = 1;
		localGridBagConstraints.gridy = 0;
		localGridBagConstraints.gridwidth = 1;
		localGridBagConstraints.gridheight = 1;
		localGridBagConstraints.weightx = 1.0D;

		this.ipText = new JTextField();
		if (this.hostIP == null) {
			this.ipText.setText("");
		} else
			this.ipText.setText(this.hostIP);
		this.ipText.addKeyListener(this.keyListener);
		this.ipText.addFocusListener(this.textFieldFocusListener);
		this.textPanel.add(this.ipText, localGridBagConstraints);

		localGridBagConstraints.insets = new Insets(5, 10, 5, 10);
		localGridBagConstraints.gridy = 1;

		this.portText = new JTextField();
		if (this.secWebPort < 0) {
			this.portText.setText("");
		} else
			this.portText.setText(String.valueOf(this.secWebPort));
		this.portText.addKeyListener(this.keyListener);
		this.portText.addFocusListener(this.textFieldFocusListener);
		this.textPanel.add(this.portText, localGridBagConstraints);

		localGridBagConstraints.gridy = 2;

		this.unameText = new JTextField();
		this.unameText.setText(this.username);
		this.unameText.addKeyListener(this.keyListener);
		this.unameText.addFocusListener(this.textFieldFocusListener);
		this.textPanel.add(this.unameText, localGridBagConstraints);

		localGridBagConstraints.gridy = 3;

		this.passwdText = new JPasswordField();
		this.passwdText.setText(this.password);
		this.passwdText.addKeyListener(this.keyListener);
		this.passwdText.addFocusListener(this.textFieldFocusListener);
		this.textPanel.add(this.passwdText, localGridBagConstraints);

		localGridBagConstraints.gridy = 4;
		this.localeList = new JComboBox(JViewer.getSupportedLocales());
		Locale localLocale = new Locale(selectedLocale.toLowerCase());
		String str = localLocale.getDisplayLanguage(new Locale(selectedLocale));
		this.localeList.setSelectedItem(str + " - [" + selectedLocale + "]");

		this.localeList.setAutoscrolls(true);
		this.localeList.addItemListener(this);
		this.textPanel.add(this.localeList, localGridBagConstraints);

		localGridBagConstraints.gridy = 5;
		this.appTypeList = new JComboBox(getStandAloneAppType());
		this.appTypeList.setSelectedIndex(0);
		this.appTypeList.setAutoscrolls(true);
		this.appTypeList.addItemListener(this);
		this.textPanel.add(this.appTypeList, localGridBagConstraints);

		getContentPane().add(this.textPanel, "North");

		this.helpPanel = new JPanel();
		this.helpTextLabel = new JLabel(LocaleStrings.getString("S_40_SACD"));
		this.helpPanel.add(this.helpTextLabel);

		this.progressPanel = new JPanel();
		this.btnPanel = new JPanel();
		this.btnPanel.setLayout(new GridBagLayout());

		localGridBagConstraints = new GridBagConstraints();
		localGridBagConstraints.insets = new Insets(2, 15, 5, 10);
		localGridBagConstraints.weightx = 0.0D;

		this.launchBtn = new JButton(LocaleStrings.getString("S_6_SACD"));
		this.btnPanel.add(this.launchBtn, localGridBagConstraints);

		localGridBagConstraints.insets = new Insets(2, 5, 5, 10);
		localGridBagConstraints.gridx = -1;

		this.cancelBtn = new JButton(LocaleStrings.getString("S_7_SACD"));
		this.cancelBtn.addActionListener(this);
		this.cancelBtn.addKeyListener(this.keyListener);
		this.btnPanel.add(this.cancelBtn, localGridBagConstraints);

		this.bottomPanel = new JPanel();
		this.bottomPanel.setLayout(new GridBagLayout());
		localGridBagConstraints = new GridBagConstraints();
		localGridBagConstraints.insets = new Insets(5, 10, 5, 10);
		localGridBagConstraints.weightx = 1.0D;
		localGridBagConstraints.gridy = 0;
		localGridBagConstraints.gridwidth = 1;
		localGridBagConstraints.gridheight = 1;

		this.bottomPanel.add(this.helpPanel, localGridBagConstraints);
		localGridBagConstraints.insets = new Insets(0, 0, 10, 0);
		localGridBagConstraints.weightx = 1.0D;

		localGridBagConstraints.gridy = 1;
		localGridBagConstraints.fill = 0;
		this.bottomPanel.add(this.btnPanel, localGridBagConstraints);
		getContentPane().add(this.bottomPanel, "South");
		setAlwaysOnTop(true);
		pack();
		JViewerApp.getOEMManager().getOEMStandAloneConnectionDialog().customizeDialogComponents(getContentPane());
	}

	private void clearDialog() {
		getContentPane().removeAll();
		this.textPanel.removeAll();
		this.textPanel.updateUI();
		getContentPane().add(this.textPanel, "North");
		getContentPane().add(this.btnPanel);
	}

	public abstract class MyTableModel extends AbstractTableModel {
		public MyTableModel() {
		}

		public boolean isEditable() {
			return false;
		}
	}

	private void constructTableDialog() {
		clearDialog();

		Object[] arrayOfObject = { LocaleStrings.getString("S_32_SACD"), LocaleStrings.getString("S_33_SACD") };

		this.model = new DefaultTableModel((Object[][]) null, arrayOfObject);
		this.videoTable = new JTable(this.model) {
			public boolean isCellEditable(int paramAnonymousInt1, int paramAnonymousInt2) {
				return false;
			}
		};
		this.textPanel.setLayout(new GridBagLayout());
		GridBagConstraints localGridBagConstraints1 = new GridBagConstraints();
		GridBagConstraints localGridBagConstraints2 = new GridBagConstraints();

		localGridBagConstraints1.fill = 1;
		localGridBagConstraints1.insets = new Insets(10, 10, 5, 10);
		localGridBagConstraints1.gridx = 0;
		localGridBagConstraints1.gridy = 0;
		localGridBagConstraints1.gridwidth = 1;
		localGridBagConstraints1.gridheight = 1;
		localGridBagConstraints1.weightx = 1.0D;
		localGridBagConstraints1.weighty = 0.5D;

		JTableHeader localJTableHeader1 = this.videoTable.getTableHeader();
		localJTableHeader1.setFont(new Font("Tahoma", 1, 12));

		this.videoTable.setCellEditor(null);

		this.videoTable.addKeyListener(this.keyListener);
		this.videoTable.addMouseListener(new MouseAdapter() {
			public void mouseClicked(MouseEvent paramAnonymousMouseEvent) {
				if (!buttonsEnabled) {
					enableDialog();
					buttonsEnabled = true;
				}
			}
		});
		this.videoTable.setBackground(Color.white);
		JTableHeader localJTableHeader2 = this.videoTable.getTableHeader();

		Border localBorder = BorderFactory.createEtchedBorder(1);
		TitledBorder localTitledBorder = BorderFactory.createTitledBorder(localBorder, "", 1, 1);

		localJTableHeader2.setBorder(localTitledBorder);
		this.videoTable.getTableHeader().setPreferredSize(new Dimension(50, 23));

		JScrollPane localJScrollPane = new JScrollPane(this.videoTable);
		localGridBagConstraints1.gridy = 1;
		this.textPanel.add(localJScrollPane, localGridBagConstraints1);

		this.helpPanel.removeAll();
		this.helpPanel.setLayout(new GridBagLayout());
		localGridBagConstraints2 = new GridBagConstraints();
		localGridBagConstraints2.insets = new Insets(0, 10, 5, 10);
		localGridBagConstraints2.fill = 2;
		localGridBagConstraints2.gridx = 0;
		localGridBagConstraints2.gridy = 0;
		localGridBagConstraints2.gridwidth = 1;
		localGridBagConstraints2.gridheight = 1;
		localGridBagConstraints2.weightx = 1.0D;
		this.videoOption = new ButtonGroup();

		this.playVideoRBtn = new JRadioButton(LocaleStrings.getString("S_30_SACD"));
		this.playVideoRBtn.setSelected(true);
		this.videoOption.add(this.playVideoRBtn);
		this.helpPanel.add(this.playVideoRBtn, localGridBagConstraints2);

		localGridBagConstraints2.gridx = 1;
		this.saveVideoRBtn = new JRadioButton(LocaleStrings.getString("S_31_SACD"));
		this.videoOption.add(this.saveVideoRBtn);
		this.helpPanel.add(this.saveVideoRBtn, localGridBagConstraints2);
		this.helpPanel.revalidate();
		this.helpPanel.repaint();

		localGridBagConstraints1.gridy = 2;
		localGridBagConstraints1.weighty = 0.0D;
		this.textPanel.add(this.helpPanel, localGridBagConstraints1);

		localGridBagConstraints1.gridy = 3;
		this.textPanel.add(this.btnPanel, localGridBagConstraints1);

		this.launchBtn.setText(LocaleStrings.getString("A_3_GLOBAL"));

		this.textPanel.updateUI();
		getContentPane().add(this.textPanel);
		setTitle(LocaleStrings.getString("S_29_SACD"));
	}

	private void showDialog() {
		disableDialog();
		this.validate = true;
		this.validator = new Validator();
		this.validator.start();
		setVisible(true);
	}

	private JDialog getDialog() {
		return this;
	}

	public JProgressBar getProgressBar() {
		return this.launchProgressBar;
	}

	private void enableDialog() {
		if ((JViewer.isStandAloneApp()) || (JViewer.isVMApp()))
			setDialogTitle(LocaleStrings.getString("S_1_SACD"));
		this.ipText.setEditable(true);
		this.portText.setEditable(true);
		this.unameText.setEditable(true);
		this.passwdText.setEditable(true);
		this.launchBtn.setEnabled(true);
		this.launchBtn.addActionListener(this);
		this.launchBtn.addKeyListener(this.keyListener);
		String str = JViewer.getLaunch();

		if ((JViewer.isStandAloneSupportedApps(str)) && (this.firstCheck)) {

			if (str.compareToIgnoreCase("JViewer") == 0) {
				this.appTypeList.setSelectedIndex(0);
				JViewer.setApptype("StandAlone");
			} else if (str.compareToIgnoreCase("VMApp") == 0) {
				this.appTypeList.setSelectedIndex(1);
				JViewer.setApptype("VMApp");
			} else if (str.compareToIgnoreCase("SaveVideo") == 0) {
				this.appTypeList.setSelectedIndex(2);
				JViewer.setApptype("SaveVideo");
			} else if (str.compareToIgnoreCase("PlayVideo") == 0) {
				this.appTypeList.setSelectedIndex(2);
				JViewer.setApptype("PlayVideo");
			}
			this.appTypeList.setEnabled(false);

		} else if (!JViewer.isStandAloneSupportedApps(str)) {
			this.appTypeList.setEnabled(true);
		}

		if ((!JViewer.isDefaultLang()) && (this.firstCheck)) {
			this.localeList.setEnabled(false);

		} else if (JViewer.isDefaultLang()) {
			this.localeList.setEnabled(true);
		}

		showProgress(false);
		setVisible(true);
	}

	private void disableDialog() {
		setDialogTitle(LocaleStrings.getString("S_8_SACD"));
		this.launchBtn.requestFocus();
		this.ipText.setEditable(false);
		this.portText.setEditable(false);
		this.unameText.setEditable(false);
		this.passwdText.setEditable(false);
		this.launchBtn.setEnabled(false);
		this.launchBtn.removeActionListener(this);
		this.launchBtn.removeKeyListener(this.keyListener);
		this.localeList.setEnabled(false);
		this.appTypeList.setEnabled(false);
		showProgress(true);
	}

	private void showProgress(boolean paramBoolean) {
		GridBagConstraints localGridBagConstraints = new GridBagConstraints();
		localGridBagConstraints.fill = 2;
		localGridBagConstraints.weightx = 1.0D;
		localGridBagConstraints.gridy = 0;
		localGridBagConstraints.gridwidth = 1;
		localGridBagConstraints.gridheight = 1;
		if (paramBoolean) {
			this.helpTextLabel.setText("");
			this.bottomPanel.remove(this.helpPanel);
			this.progressPanel.removeAll();
			this.progressPanel.setLayout(new GridBagLayout());
			localGridBagConstraints.insets = new Insets(15, 0, 0, 0);
			localGridBagConstraints.ipady = 5;
			this.launchProgressBar = new JProgressBar();
			this.progressPanel.add(this.launchProgressBar, localGridBagConstraints);
			this.launchProgressBar.setString(LocaleStrings.getString("S_8_SACD"));
			this.launchProgressBar.setStringPainted(true);
			this.launchProgressBar.setIndeterminate(true);
			localGridBagConstraints.insets = new Insets(10, 10, 5, 10);
			localGridBagConstraints.ipady = 0;
			this.bottomPanel.add(this.progressPanel, localGridBagConstraints);
		} else {
			this.bottomPanel.remove(this.progressPanel);
			if ((JViewer.isStandAloneApp()) || (JViewer.isVMApp())) {
				localGridBagConstraints.insets = new Insets(5, 10, 5, 10);
				this.helpTextLabel.setText(LocaleStrings.getString("S_40_SACD"));
				this.bottomPanel.add(this.helpPanel, localGridBagConstraints);
			} else {
				this.helpTextLabel.setText("");
			}
			repaint();
		}
	}

	private int getWebSessionToken() {
		int i = -1;
		this.urlProcessor = new URLProcessor(null, 1);
		this.urlProcessor.setHostIP(this.hostIP);
		i = this.urlProcessor.processRequest("https://" + this.hostIP + ":" + this.secWebPort
				+ "/rpc/WEBSES/create.asp?WEBVAR_USERNAME=" + this.username + "&WEBVAR_PASSWORD=" + this.password);

		try {
			if (i == -6) {
				this.validate = false;
				enableDialog();
				this.ipText.setText(JViewer.getIp());
				this.unameText.setText(null);
				this.passwdText.setText(null);
				JOptionPane.showMessageDialog(getDialog(), LocaleStrings.getString("S_10_SACD"),
						JViewer.getTitle() + LocaleStrings.getString("S_9_SACD"), 0);

				this.unameText.requestFocus();
			} else if (i == 0) {
				getProgressBar().setString(LocaleStrings.getString("S_44_SACD"));
				this.webSessionToken = this.urlProcessor.getValue("'SESSION_COOKIE' : '", ',');
				this.webSessionToken.trim();
				this.webSessionToken = this.webSessionToken.substring(0, this.webSessionToken.lastIndexOf('\''));
				JViewer.setWebSessionToken(this.webSessionToken);
				JViewer.setPassword(this.password);
			} else if (i == -1) {
				showProgress(false);
				JOptionPane.showMessageDialog(getDialog(), LocaleStrings.getString("S_11_SACD"),
						LocaleStrings.getString("S_9_SACD"), 0);

				this.windowListener.windowClosing(null);
			} else if (i == -7) {
				this.windowListener.windowClosing(null);
			}
		} catch (Exception localException) {
			Debug.out.println(localException);
			showProgress(false);
			JOptionPane.showMessageDialog(getDialog(), LocaleStrings.getString("S_11_SACD"),
					LocaleStrings.getString("S_9_SACD"), 0);

			this.windowListener.windowClosing(null);
		}
		return i;
	}

	private int getKVMPrivilege() {
		int i = 0;
		this.urlProcessor = new URLProcessor(this.webSessionToken, 1);
		int j = this.urlProcessor.processRequest("https://" + this.hostIP + ":" + this.secWebPort + "/rpc/getrole.asp");
		try {
			if (j == 0) {
				getProgressBar().setString(LocaleStrings.getString("S_45_SACD"));
				i = Integer.parseInt(this.urlProcessor.getValue("'EXTENDED_PRIV' : ", ' '));
			} else if (j == -7) {
				this.windowListener.windowClosing(null);
			}
		} catch (Exception localException) {
			Debug.out.println(localException);
			i = -1;
		}
		JViewer.setKVMPrivilege(i);
		if (JViewer.isStandAloneApp()) {
			if (!JViewer.isKVMEnabled()) {
				resetDialogAndShowMessage(
						LocaleStrings.getString("S_12_SACD") + this.username + LocaleStrings.getString("S_13_SACD"));

				j = -1;
			}
		} else if ((JViewer.isVMApp()) && (!JViewer.isVMediaEnabled())) {
			resetDialogAndShowMessage(
					LocaleStrings.getString("S_12_SACD") + this.username + LocaleStrings.getString("S_43_SACD"));

			j = -1;
		}

		return j;
	}

	private void getAdviserSessionToken() {
		String str = null;
		this.urlProcessor = new URLProcessor(this.webSessionToken, 1);
		int i = this.urlProcessor
				.processRequest("https://" + this.hostIP + ":" + this.secWebPort + "/rpc/getsessiontoken.asp");
		try {
			if (i == 0) {
				getProgressBar().setString(LocaleStrings.getString("S_49_SACD"));
				str = this.urlProcessor.getValue("'SESSION_TOKEN' : '", ',');
				str.trim();
				str = str.substring(0, str.lastIndexOf('\''));
				JViewer.setSessionCookies(str);

			} else if (i == -1) {
				showProgress(false);
				JOptionPane.showMessageDialog(this, LocaleStrings.getString("S_11_SACD"),
						LocaleStrings.getString("S_9_SACD"), 0);

				this.windowListener.windowClosing(null);
			} else if (i == -7) {
				this.windowListener.windowClosing(null);
			}
		} catch (Exception localException) {
			Debug.out.println(localException);
			showProgress(false);
			JOptionPane.showMessageDialog(this, LocaleStrings.getString("S_11_SACD"),
					LocaleStrings.getString("S_9_SACD"), 0);

			this.windowListener.windowClosing(null);
		}
	}

	private void getAdviserConfig() {
		int n = 12;
		int i1 = 10;
		long l = 0L;
		byte b = 0;
		String str = "AD";
		this.urlProcessor = new URLProcessor(this.webSessionToken, 1);
		try {
			int i2 = this.urlProcessor
					.processRequest("https://" + this.hostIP + ":" + this.secWebPort + "/rpc/getadvisercfg.asp");
			if (i2 == 0) {
				getProgressBar().setString(LocaleStrings.getString("S_46_SACD"));
				int i = Integer.parseInt(this.urlProcessor.getValue("'V_STR_KVM_STATUS' : ", ','));
				if (i == 0) {
					JOptionPane.showMessageDialog(this, LocaleStrings.getString("S_14_SACD"),
							LocaleStrings.getString("S_9_SACD"), 0);

					this.windowListener.windowClosing(null);
				}
				int j = Integer.parseInt(this.urlProcessor.getValue("'V_STR_SECURE_CHANNEL' : ", ','));
				JViewer.setSecureChannel(j);

				int k = Integer.parseInt(this.urlProcessor.getValue("'V_STR_KVM_PORT' : ", ','));
				int m = Integer.parseInt(this.urlProcessor.getValue("'V_STR_WEB_PORT' : ", ','));

				if (JViewer.isSinglePortEnabled() == true) {

					JViewer.setKVMPort(m);

					JViewer.setUseSSL(true);
				} else {
					JViewer.setKVMPort(k);

					if (j == 0) {
						JViewer.setUseSSL(false);
					} else if (j == 1) {
						JViewer.setUseSSL(true);
					}
				}
				try {
					l = Long.parseLong(this.urlProcessor.getValue("'V_STR_OEM_FEATURE_STATUS' : ", ' '));
					JViewer.setOEMFeatureStatus(l);
				} catch (NumberFormatException localNumberFormatException1) {
					Debug.out.println(localNumberFormatException1);
					JOptionPane.showMessageDialog(this, LocaleStrings.getString("S_36_SACD"),
							LocaleStrings.getString("S_9_SACD"), 0);

					l = 0L;
				} catch (Exception localException2) {
					Debug.out.println(localException2);
					JOptionPane.showMessageDialog(this, LocaleStrings.getString("S_36_SACD"),
							LocaleStrings.getString("S_9_SACD"), 0);

					l = 0L;
				}

				if ((JViewer.getOEMFeatureStatus() & 0x20) == 32L) {
					JViewer.setKVMReconnectEnabled(true);
					try {
						n = Integer.parseInt(this.urlProcessor.getValue("'V_STR_RETRY_COUNT' : ", ','));
					} catch (NumberFormatException localNumberFormatException2) {
						Debug.out.println(localNumberFormatException2);
						JOptionPane.showMessageDialog(this, LocaleStrings.getString("S_40_SACD"),
								LocaleStrings.getString("S_9_SACD"), 0);
					} catch (Exception localException3) {
						Debug.out.println(localException3);
						JOptionPane.showMessageDialog(this, LocaleStrings.getString("S_40_SACD"),
								LocaleStrings.getString("S_9_SACD"), 0);
					}

					JViewer.setRetryCount(n);
					try {
						i1 = Integer.parseInt(this.urlProcessor.getValue("'V_STR_RETRY_INTERVAL' : ", ','));
					} catch (NumberFormatException localNumberFormatException3) {
						Debug.out.println(localNumberFormatException3);
						JOptionPane.showMessageDialog(this, LocaleStrings.getString("S_39_SACD"),
								LocaleStrings.getString("S_9_SACD"), 0);
					} catch (Exception localException4) {
						Debug.out.println(localException4);
						JOptionPane.showMessageDialog(this, LocaleStrings.getString("S_39_SACD"),
								LocaleStrings.getString("S_9_SACD"), 0);
					}

					JViewer.setRetryInterval(i1);
				}

				try {
					b = Byte.parseByte(this.urlProcessor.getValue("'V_STR_KVM_LICENSE_STATUS' : ", ','));
					JViewer.setKVMLicenseStatus(b);
				} catch (NumberFormatException localNumberFormatException4) {
					Debug.out.print(localNumberFormatException4);
					JOptionPane.showMessageDialog(this, LocaleStrings.getString("S_37_SACD"),
							LocaleStrings.getString("S_9_SACD"), 0);

					JViewer.setKVMLicenseStatus((byte) 0);
				} catch (Exception localException5) {
					Debug.out.print(localException5);
					JOptionPane.showMessageDialog(this, LocaleStrings.getString("S_37_SACD"),
							LocaleStrings.getString("S_9_SACD"), 0);

					JViewer.setKVMLicenseStatus((byte) 0);
				}

				try {
					str = this.urlProcessor.getValue("'V_STR_KEYBOARD_LAYOUT' : ", ',');
					if ((str.startsWith("'")) && (str.endsWith("'"))) {
						try {
							int i3 = str.indexOf('\'') + 1;
							int i4 = str.lastIndexOf('\'');
							str = str.substring(i3, i4);
						} catch (IndexOutOfBoundsException localIndexOutOfBoundsException) {
							Debug.out.println(localIndexOutOfBoundsException);
							str = "AD";
						} catch (Exception localException6) {
							Debug.out.println(localException6);
							str = "AD";
						}
					}
				} catch (Exception localException7) {
					Debug.out.println(localException7);
					str = "AD";
				}
				JViewer.setKeyboardLayout(str);

				JViewer.setKVM_Num_FD(JViewer.getKVM_Num_FD());
				JViewer.setKVM_Num_CD(JViewer.getKVM_Num_CD());
				JViewer.setKVM_Num_HD(JViewer.getKVM_Num_HD());
			} else if (i2 == -1) {
				JOptionPane.showMessageDialog(this, LocaleStrings.getString("S_15_SACD"),
						LocaleStrings.getString("S_9_SACD"), 0);

				this.windowListener.windowClosing(null);
			} else if (i2 == -7) {
				this.windowListener.windowClosing(null);
			}
		} catch (Exception localException1) {
			Debug.out.println(localException1);
			JOptionPane.showMessageDialog(this, LocaleStrings.getString("S_15_SACD"),
					LocaleStrings.getString("S_9_SACD"), 0);

			this.windowListener.windowClosing(null);
		}
	}

	private String[][] findVideoData(String paramString) {
		String str1 = null;
		String str2 = null;
		if (JViewer.isRestService() == true) {
			str1 = "\"file\": \"";
			str2 = "\"fileinfo\": \"";
		} else {
			str1 = "'FILE_NAME' : '";
			str2 = "'FILE_INFO' : '";
		}

		int i = 0;
		int j = 0;
		int k = 0;
		int m = 0;
		int n = 0;
		int i1 = 2;
		int i2 = -1;

		int i3 = getOccurances(paramString, str1);
		if (i3 > 0) {
			this.videoFile = new String[i3][i1];
			String str5 = paramString;
			while (m < i3) {
				n = 0;
				String str4 = null;
				String str3 = null;
				str3 = str1;

				str4 = str5 = str5.substring(j);
				i = str4.indexOf(str1);
				str4 = str4.substring(i);

				k = j = str4.indexOf("}");

				if ((i > 0) && (j > 0)) {
					str4 = str4.substring(0, j);

					while (n < i1) {
						if (str3 == null) {
							str3 = str2;
							str4 = str4.substring(str4.indexOf(str3));
						}

						j = str4.indexOf("\",", str3.length());
						if (j < 0) {
							j = str4.indexOf('\\');
						}

						this.videoFile[m][n] = str4.substring(str3.length(), j).trim();

						this.videoFile[m][n].trim();
						i2 = this.videoFile[m][n].indexOf('\\');
						if (i2 >= 0) {
							String str6 = this.videoFile[m][n].substring(0, i2)
									+ this.videoFile[m][n].substring(i2 + 1);
							this.videoFile[m][n] = str6;
						}

						if (this.videoFile[m][n].indexOf('\'') > 0) {
							this.videoFile[m][n] = this.videoFile[m][n].substring(0, this.videoFile[m][n].indexOf(39));
						}

						if (str3.equalsIgnoreCase(str2)) {
							i2 = this.videoFile[m][0].lastIndexOf('/');
							if (i2 == -1) {
								i2 = 0;
							} else
								i2++;
							this.model
									.addRow(new Object[] { this.videoFile[m][0].substring(i2), this.videoFile[m][1] });
						}

						n++;
						str3 = null;
					}
				}
				j = i + k + 1;
				m++;
			}
		}

		JOptionPane.showMessageDialog(this, LocaleStrings.getString("S_28_SACD"), LocaleStrings.getString("A_6_GLOBAL"),
				1);

		this.windowListener.windowClosing(null);

		return this.videoFile;
	}

	public int getOccurances(String paramString1, String paramString2) {
		int i = 0;
		int j = 0;
		String str = new String(paramString1);

		while ((j = str.indexOf(paramString2, j)) != -1) {
			i++;
			j += paramString2.length();
		}
		return i;
	}

	private void getVideoInfo() {
		String str = null;
		int i = -1;

		constructTableDialog();

		this.urlProcessor = new URLProcessor(this.webSessionToken, 1);
		try {
			if (JViewer.isRestService() == true) {
				this.urlProcessor.setHostIP(this.hostIP);
				i = this.urlProcessor
						.restProcessRequest("https://" + this.hostIP + ":" + this.secWebPort + "/api/logs/video");
			} else {
				i = this.urlProcessor
						.processRequest("https://" + this.hostIP + ":" + this.secWebPort + "/rpc/getvideoinfo.asp");
			}
			if (i == 0) {
				str = new String(this.urlProcessor.getData());
				findVideoData(str);

				getContentPane().invalidate();
				getContentPane().validate();
			} else if (i == -1) {
				JOptionPane.showMessageDialog(this, LocaleStrings.getString("S_25_SACD"),
						LocaleStrings.getString("S_9_SACD"), 0);

				this.windowListener.windowClosing(null);
			} else if (i == -7) {
				this.windowListener.windowClosing(null);
			}
		} catch (Exception localException) {
			Debug.out.println(localException);
			JOptionPane.showMessageDialog(this, LocaleStrings.getString("S_25_SACD"),
					LocaleStrings.getString("S_9_SACD"), 0);

			this.windowListener.windowClosing(null);
		}
	}

	private void getVMediaConfig() {
		this.urlProcessor = new URLProcessor(this.webSessionToken, 1);
		int j = this.urlProcessor
				.processRequest("https://" + this.hostIP + ":" + this.secWebPort + "/rpc/getvmediacfg.asp");

		if (j == 0) {
			try {
				getProgressBar().setString(LocaleStrings.getString("S_47_SACD"));
				String str = this.urlProcessor.getValue("'V_SINGLE_PORT_ENABLED' : ", ',');

				if (1 == Integer.parseInt(str)) {
					JViewer.setSinglePortEnabled(true);
				} else {
					JViewer.setSinglePortEnabled(false);
				}
				str = this.urlProcessor.getValue("'V_MEDIA_LICENSE_STATUS' : ", ',');
				JViewer.setMediaLicenseStatus((byte) Integer.parseInt(str));

				if (!JViewer.isSinglePortEnabled()) {
					str = this.urlProcessor.getValue("'V_STR_SECURE_CHANNEL' : ", ',');
					int i = Integer.parseInt(str);
					JViewer.setVMSecureChannel(i);

					if (i == 0) {
						JViewer.setVMUseSSL(false);
						str = this.urlProcessor.getValue("'V_STR_CD_PORT' : ", ',');
						JViewer.setCdserver_port(Integer.parseInt(str));
						str = this.urlProcessor.getValue("'V_STR_FD_PORT' : ", ',');
						JViewer.setFdserver_port(Integer.parseInt(str));
						str = this.urlProcessor.getValue("'V_STR_HD_PORT' : ", ',');
						JViewer.setHdserver_port(Integer.parseInt(str));
					} else if (i == 1) {
						JViewer.setVMUseSSL(true);
						str = this.urlProcessor.getValue("'V_STR_CD_SECURE_PORT' : ", ',');
						JViewer.setCdserver_port(Integer.parseInt(str));
						str = this.urlProcessor.getValue("'V_STR_FD_SECURE_PORT' : ", ',');
						JViewer.setFdserver_port(Integer.parseInt(str));
						str = this.urlProcessor.getValue("'V_STR_HD_SECURE_PORT' : ", ',');
						JViewer.setHdserver_port(Integer.parseInt(str));
					}
				}

				str = this.urlProcessor.getValue("'V_NUM_FD' : ", ',');
				JViewer.setNum_FD((byte) Integer.parseInt(str));

				str = this.urlProcessor.getValue("'V_NUM_CD' : ", ',');
				JViewer.setNum_CD((byte) Integer.parseInt(str));

				str = this.urlProcessor.getValue("'V_NUM_HD' : ", ',');
				JViewer.setNum_HD((byte) Integer.parseInt(str));

				str = this.urlProcessor.getValue("'V_CD_STATUS' : ", ',');
				JViewer.setCD_State(Integer.parseInt(str));
				str = this.urlProcessor.getValue("'V_FD_STATUS' : ", ',');
				JViewer.setFD_State(Integer.parseInt(str));
				str = this.urlProcessor.getValue("'V_HD_STATUS' : ", ',');
				JViewer.setHD_State(Integer.parseInt(str));

				str = this.urlProcessor.getValue("'V_KVM_NUM_FD' : ", ',');
				JViewer.setKVM_Num_FD((byte) Integer.parseInt(str));

				str = this.urlProcessor.getValue("'V_KVM_NUM_CD' : ", ',');
				JViewer.setKVM_Num_CD((byte) Integer.parseInt(str));

				str = this.urlProcessor.getValue("'V_KVM_NUM_HD' : ", ',');
				JViewer.setKVM_Num_HD((byte) Integer.parseInt(str));
				str = this.urlProcessor.getValue("'V_POWER_SAVE_MODE' : ", ' ');
				if (str != null) {
					JViewer.setPowerSaveMode((byte) Integer.parseInt(str));
				} else {
					Debug.out.println("V_POWER_SAVE_MODE not found in the response data");
				}
			} catch (NumberFormatException localNumberFormatException) {
				Debug.out.println(localNumberFormatException);
				JOptionPane.showMessageDialog(this, LocaleStrings.getString("S_16_SACD"),
						LocaleStrings.getString("S_9_SACD"), 0);

				this.windowListener.windowClosing(null);
			} catch (NullPointerException localNullPointerException) {
				Debug.out.println(localNullPointerException);
				JOptionPane.showMessageDialog(this, LocaleStrings.getString("S_16_SACD"),
						LocaleStrings.getString("S_9_SACD"), 0);

				this.windowListener.windowClosing(null);
			}
		} else if (j == -1) {
			JOptionPane.showMessageDialog(this, LocaleStrings.getString("S_16_SACD"),
					LocaleStrings.getString("S_9_SACD"), 0);

			this.windowListener.windowClosing(null);
		} else if (j == -7) {
			this.windowListener.windowClosing(null);
		}
	}

	public void logoutWebSession() {
		if (JViewer.getWebSessionToken() == null) {
			return;
		}
		if (JViewer.isKVMReconnectEnabled()) {
			if (JViewerApp.getInstance().getRetryConnection()) {
				return;
			}
		}

		if ((!JViewer.isStandAloneApp()) && (!JViewer.isVMApp())
				&& (JViewerApp.getInstance().getVideorecordapp() != null)) {
			JViewerApp.getInstance().getVideorecordapp().lockVideoFile(false);
		}

		if (this.webLogIn) {
			int i = -1;
			this.urlProcessor = new URLProcessor(JViewer.getWebSessionToken(), 1);
			if (JViewer.isRestService() == true) {
				i = this.urlProcessor
						.restProcessRequest("https://" + this.hostIP + ":" + this.secWebPort + "/api/session");
			} else {
				i = this.urlProcessor
						.processRequest("https://" + this.hostIP + ":" + this.secWebPort + "/rpc/WEBSES/logout.asp");
			}
			if (i != 0) {
				JOptionPane.showMessageDialog(this, LocaleStrings.getString("S_17_SACD"),
						LocaleStrings.getString("S_18_SACD"), 1);
			} else {
				this.webLogIn = false;
				URLProcessor.setCsrfToken(null);
				if (JViewerApp.getInstance().getM_webSession_token() != null) {
					JViewerApp.getInstance().setM_webSession_token(null);
				}
			}
		}
		try {
			if (URLProcessor.getSocket() != null) {
				URLProcessor.getSocket().close();
				URLProcessor.setSocket(null);
			}
		} catch (IOException localIOException) {
			Debug.out.println("Exception: while closing the socket : " + localIOException);
		}
	}

	private void manageVideo() {
		int i = this.videoTable.getSelectedRowCount();
		int[] arrayOfInt = this.videoTable.getSelectedRows();
		int j = 0;
		String[] arrayOfString = new String[i];
		if (i > 0) {
			try {
				while (j < i) {
					arrayOfString[j] = this.videoFile[arrayOfInt[j]][0];

					j++;
				}
			} catch (Exception localException) {
				Debug.out.println(localException);
			}

			if (arrayOfString.length > 0) {
				JViewer.setVideoFile(arrayOfString);
				setVisible(false);
				dispose();
				JViewerApp.getInstance().constructUI();
				JViewer.recording();
			} else {
				JOptionPane.showMessageDialog(this, LocaleStrings.getString("S_34_SACD"),
						LocaleStrings.getString("S_26_SACD"), 1);
			}

		} else {
			JOptionPane.showMessageDialog(this, LocaleStrings.getString("S_34_SACD"),
					LocaleStrings.getString("S_26_SACD"), 1);
		}
	}

	private void selectAppType() {
		if (this.appType == 0) {
			JViewer.setApptype("StandAlone");
			onConnectBtn();
		} else if (this.appType == 1) {
			JViewer.setApptype("VMApp");
			onConnectBtn();

		} else if (this.appType == 2) {
			if (this.launchBtn.getText().equals(LocaleStrings.getString("A_3_GLOBAL"))) {
				if (this.playVideoRBtn.isSelected()) {
					if (this.videoTable.getSelectedRowCount() == 1) {
						JViewer.setApptype("PlayVideo");
						manageVideo();
					} else {
						JOptionPane.showMessageDialog(JViewerApp.getInstance().getConnectionDialog(),
								LocaleStrings.getString("S_35_SACD"), LocaleStrings.getString("S_26_SACD"), 1);

					}

				} else if (this.saveVideoRBtn.isSelected()) {
					JViewer.setApptype("SaveVideo");
					manageVideo();
				}
			} else {
				JViewer.setApptype("SaveVideo");
				onConnectBtn();
			}
		}
	}

	public void actionPerformed(ActionEvent paramActionEvent) {
		if (paramActionEvent.getSource().equals(this.launchBtn)) {
			selectAppType();
		} else if (paramActionEvent.getSource().equals(this.cancelBtn)) {
			onCancelBtn();
		}
	}

	private void onConnectBtn() {
		this.hostIP = this.ipText.getText();
		this.secWebPort = JViewer.getWebPortNumber(this.portText.getText());
		this.username = this.unameText.getText();
		this.password = " ";
		char[] arrayOfChar = this.passwdText.getPassword();
		for (int i = 0; i < arrayOfChar.length; i++) {
			this.password += arrayOfChar[i];
			arrayOfChar[i] = '\000';
		}
		this.password = this.password.trim();
		showDialog();
	}

	private void onConnectionSuccess() {
		this.validate = false;
		showProgress(false);
		if ((!JViewer.isplayerapp()) && (!JViewer.isdownloadapp())) {
			setVisible(false);
			dispose();
		}
		if (JViewer.isStandAloneApp()) {
			JViewerApp.getInstance().constructUI();
			JViewer.redirect();
		} else if (JViewer.isVMApp()) {
			VMApp.launchApp();

			logoutWebSession();
		}
	}

	private void onCancelBtn() {
		if (isWebLogIn()) {
			logoutWebSession();
		}
		dispose();
		this.windowListener.windowClosing(null);
	}

	private String getDialogTitle() {
		return getTitle().trim();
	}

	private void setDialogTitle(String paramString) {
		setTitle(paramString);
	}

	public DialogWindowListener getWindowListener() {
		return this.windowListener;
	}

	class DialogKeyListener extends KeyAdapter {
		DialogKeyListener() {
		}

		public void keyPressed(KeyEvent paramKeyEvent) {
			if (paramKeyEvent.getKeyCode() == 10) {
				if (paramKeyEvent.getSource().equals(cancelBtn)) {
					onCancelBtn();
				} else {
					selectAppType();
				}
			}
		}
	}

	class DialogWindowListener extends WindowAdapter {
		DialogWindowListener() {
		}

		public void windowClosing(WindowEvent paramWindowEvent) {
			if (webLogIn)
				logoutWebSession();
			JViewer.exit(0);
		}
	}

	class TextFieldFocusListener extends FocusAdapter {
		TextFieldFocusListener() {
		}

		public void focusGained(FocusEvent paramFocusEvent) {
			if ((paramFocusEvent.getSource().toString().contains("JTextField"))
					|| (paramFocusEvent.getSource().toString().contains("JPasswordField"))) {
				JTextField localJTextField = (JTextField) paramFocusEvent.getSource();
				localJTextField.selectAll();
			}
		}
	}

	class Validator extends Thread {
		Validator() {
		}

		public void run() {
			while (validate) {
				String str1 = "";
				JTextField localJTextField = null;
				if ((hostIP == null)
						|| (hostIP.length() == 0)) {
					str1 = str1 + "\n* " + LocaleStrings.getString("S_2_SACD");
					localJTextField = ipText;

				} else if (JViewer.getServerIP(hostIP) == null) {
					str1 = str1 + "\n* " + LocaleStrings.getString("S_2_SACD");
					ipText.selectAll();
					localJTextField = ipText;
				} else {
					JViewer.setServerIP(JViewer.getServerIP(hostIP));
					hostIP = JViewer.getIp();
				}

				if (secWebPort < 0) {
					str1 = str1 + "\n* " + LocaleStrings.getString("S_3_SACD");
					portText.setText("");
					if (localJTextField == null) {
						localJTextField = portText;
					}
				} else {
					JViewer.setWebPort(secWebPort);

					JViewer.setWebSecure(1);
				}
				if ((username == null)
						|| (username.length() == 0)) {
					str1 = str1 + "\n* " + LocaleStrings.getString("S_4_SACD");
					if (localJTextField == null) {
						localJTextField = unameText;
					}
				} else {
					JViewer.setUsername(username);
				}

				if (str1.length() != 0) {
					validate = false;
					firstCheck = false;
					enableDialog();

					if ((JViewer.getArgLength() > 0) || (!firstCheck)) {
						JOptionPane.showMessageDialog(getDialog(),
								LocaleStrings.getString("S_19_SACD") + str1, LocaleStrings.getString("S_9_SACD"), 1);
					}

					firstCheck = false;
					localJTextField.requestFocus();
					localJTextField.selectAll();
					return;
				}

				JViewer.setWebSecure(1);
				int i = JViewerApp.getOEMManager().getOEMAuthentication().authenticate(
						username, password);
				if (i == 0) {

					int j = restGetCSRFToken();
					// tianlin 
					j = 0;
					if (j < 0) {
						if (j == -6) {
							validate = false;
							return;
						}

						JViewer.setRestService(false);
						if (getWebSessionToken() < 0) {
							validate = false;
							return;
						}

						webLogIn = true;
						if (getKVMPrivilege() < 0) {
							validate = false;
							logoutWebSession();
							return;
						}
						getVMediaConfig();
						getAdviserConfig();
						getAdviserSessionToken();
					} else {
						JViewer.setRestService(true);
						webLogIn = true;

						if (JViewer.isStandAloneApp()) {
							if (!JViewer.isKVMEnabled()) {
								resetDialogAndShowMessage(
										LocaleStrings.getString("S_12_SACD") + username
												+ LocaleStrings.getString("S_13_SACD"));

								validate = false;
								logoutWebSession();
							}

						} else if (JViewer.isVMApp()) {
							if (!JViewer.isVMediaEnabled()) {
								resetDialogAndShowMessage(
										LocaleStrings.getString("S_12_SACD") + username
												+ LocaleStrings.getString("S_43_SACD"));

								validate = false;
								logoutWebSession();
								return;
							}
						}
						restGetVMediaConfig();
						restGetAdviserConfig();
						restGetAdviserSessionToken();
					}
					if (JViewer.isStandAloneApp()) {
						if (JViewer.getKVMLicenseStatus() != 1) {
							Debug.out.println("JVIEWER LICENSE STATUS : " + JViewer.getKVMLicenseStatus());
							JOptionPane.showMessageDialog(getDialog(),
									LocaleStrings.getString("1_6_JVIEWER"), LocaleStrings.getString("1_3_JVIEWER"), 0);

							windowListener.windowClosing(null);
						}
					} else if (JViewer.isVMApp()) {
						if (JViewer.getMediaLicenseStatus() != 1) {
							Debug.out.println("VMEDIA LICENSE STATUS : " + JViewer.getMediaLicenseStatus());
							JOptionPane.showMessageDialog(getDialog(),
									LocaleStrings.getString("1_7_JVIEWER"), LocaleStrings.getString("1_3_JVIEWER"), 0);

							windowListener.windowClosing(null);
						}
					} else {
						getVideoInfo();
						String str2 = JViewer.getLaunch();

						if (JViewer.isStandAloneSupportedApps(str2)) {
							if (str2.compareToIgnoreCase("SaveVideo") == 0) {
								playVideoRBtn.setEnabled(false);
								saveVideoRBtn.setSelected(true);
							} else if (str2.compareToIgnoreCase("PlayVideo") == 0) {
								playVideoRBtn.setSelected(true);
								saveVideoRBtn.setEnabled(false);
							}
						}
					}
					if ((!JViewer.isSinglePortEnabled()) && ((JViewer.isStandAloneApp()) || (JViewer.isVMApp()))) {

						logoutWebSession();
					}
					onConnectionSuccess();
				} else if (i == 1) {
					onConnectionSuccess();
				} else {
					validate = false;
					return;
				}
			}
		}
	}

	public static String replaceAllPattern(String paramString1, String paramString2, String paramString3) {
		int i = 0;
		int j = 1;
		String str = "";
		for (int k = 0; k < j; k++) {
			if ((i = paramString1.indexOf(paramString2, i)) >= 0) {
				i += paramString2.length();
				if (paramString1.indexOf(paramString2, i) == i) {
					j++;
				}
				str = str + paramString2;
			}
		}
		try {
			if (str.length() > 0) {
				paramString1 = paramString1.replaceFirst(str, paramString3);
			} else
				return paramString1;
		} catch (NullPointerException localNullPointerException) {
			Debug.out.println("REPLACE ALL PATTERN : ");
			Debug.out.println(localNullPointerException);
			return paramString1;
		}
		return replaceAllPattern(paramString1, paramString2, paramString3);
	}

	public static boolean getWrapperLibrary(String paramString) {
		String str1 = null;
		if (System.getProperty("os.arch").contains("64")) {
			if (System.getProperty("os.name").startsWith("Windows")) {
				str1 = "lib/win64/";
			} else if (System.getProperty("os.name").startsWith("Linux")) {
				str1 = "lib/linux64/";
			} else if (System.getProperty("os.name").startsWith("Mac")) {
				str1 = "lib/mac64/";
			}
		} else if (System.getProperty("os.arch").contains("86")) {
			if (System.getProperty("os.name").startsWith("Windows")) {
				str1 = "lib/win32/";
			} else if ((System.getProperty("os.name").startsWith("Linux"))
					&& (!System.getProperty("os.arch").contains("64"))) {
				str1 = "lib/linux32/";
			} else if ((System.getProperty("os.name").startsWith("Mac"))
					&& (!System.getProperty("os.arch").contains("64"))) {
				str1 = "lib/mac32/";
			}
		}
		if (paramString != null) {
			String str2 = null;
			str2 = JViewer.class.getProtectionDomain().getCodeSource().getLocation().getPath();

			str2 = str2.substring(0, str2.lastIndexOf('/'));

			if (str2.contains("%20")) {
				str2 = str2.replaceAll("%20", "\\ ");
			}

			String str3 = "Jar" + File.separator + JViewer.getIp() + File.separator + "lib";

			if ((System.getProperty("os.name").startsWith("Windows")) && (str3.contains(":"))) {
				str3 = replaceAllPattern(str3, ":", "_");
			}

			str3 = str2 + File.separator + str3;
			File localFile1 = new File(str3);
			if (!localFile1.exists()) {
				localFile1.mkdirs();
			}
			File localFile2 = new File(localFile1 + File.separator + paramString);
			try {
				InputStream localInputStream = JViewer.class.getResourceAsStream(str1 + paramString);

				if ((JViewerApp.getInstance().isLinuxClient()) || (JViewerApp.getInstance().isMacClient())) {

					if (!isUnixFileClosed(localFile2)) {
						localInputStream.close();
						return false;
					}
				}
				FileOutputStream localFileOutputStream = new FileOutputStream(localFile2);

				while (localInputStream.available() > 0) {
					localFileOutputStream.write(localInputStream.read());
				}
				localFileOutputStream.close();
				localInputStream.close();
			} catch (FileNotFoundException localFileNotFoundException) {
				Debug.out.println(localFileNotFoundException);
				return false;
			} catch (IOException localIOException) {
				Debug.out.println(localIOException);
				return false;
			} catch (Exception localException) {
				Debug.out.println(localException);
				return false;
			}
		}
		return true;
	}

	public void itemStateChanged(ItemEvent paramItemEvent) {
		if ((paramItemEvent.getSource().equals(this.localeList)) && (paramItemEvent.getStateChange() == 2)) {
			selectedLocale = (String) this.localeList.getSelectedItem();
			String str = " - [";
			int i = selectedLocale.indexOf(str) + str.length();
			int j = selectedLocale.indexOf("]");
			selectedLocale = selectedLocale.substring(i, j);
			JViewer.setLanguage(selectedLocale);

			this.localeList.removeItemListener(this);
			onLanguageChange();

			this.localeList.addItemListener(this);
		}
		if ((paramItemEvent.getSource().equals(this.appTypeList)) && (paramItemEvent.getStateChange() == 2)) {
			this.appType = this.appTypeList.getSelectedIndex();
			if (this.appType == -1) {
				this.appType = 0;
			}
			if (this.appType == 0)
				this.helpTextLabel.setText(LocaleStrings.getString("S_40_SACD"));
			if (this.appType == 1)
				this.helpTextLabel.setText(LocaleStrings.getString("S_41_SACD"));
			if (this.appType == 2) {
				this.helpTextLabel.setText(LocaleStrings.getString("S_42_SACD"));
			}
			pack();
		}
	}

	private void onLanguageChange() {
     setTitle(LocaleStrings.getString("S_1_SACD"));
     this.ipLabel.setText(LocaleStrings.getString("S_2_SACD") + " : ");
     this.portLabel.setText(LocaleStrings.getString("S_3_SACD") + " : ");
     this.unameLabel.setText(LocaleStrings.getString("S_4_SACD") + " : ");
     this.passwdLabel.setText(LocaleStrings.getString("S_5_SACD") + " : ");
     this.localeLabel.setText(LocaleStrings.getString("S_21_SACD") + " : ");
     this.appTypeLabel.setText(LocaleStrings.getString("S_34_SACD") + " : ");
     
     this.launchBtn.setText(LocaleStrings.getString("S_6_SACD"));
     this.cancelBtn.setText(LocaleStrings.getString("S_7_SACD"));
     this.helpTextLabel.setText(LocaleStrings.getString("S_40_SACD"));
     
 
     String[] arrayOfString1 = JViewer.getSupportedLocales();
     int i = this.localeList.getSelectedIndex();
     this.localeList.removeAllItems();
     for (String str1 : arrayOfString1) {
       this.localeList.addItem(str1);
     }
     this.localeList.setSelectedIndex(i);
     
 
     String[] tianlin = getStandAloneAppType();
     int tianlin_1 = this.appTypeList.getSelectedIndex();
     this.appTypeList.removeAllItems();
     for (String str2 : tianlin) {
       this.appTypeList.addItem(str2);
     }
     this.appTypeList.setSelectedIndex(tianlin_1);
     
     pack();
   }

	public static String getSelectedLocale() {
		return selectedLocale;
	}

	public static void setSelectedLocale(String paramString) {
		selectedLocale = paramString;
	}

	public int getRemotePathSupport() {
		return this.remotePathSupport;
	}

	public void setRemotePathSupport(int paramInt) {
		this.remotePathSupport = paramInt;
	}

	public boolean isWebLogIn() {
		return this.webLogIn;
	}

	public void setWebLogIn(boolean paramBoolean) {
		this.webLogIn = paramBoolean;
	}

	public URLProcessor getUrlProcessor() {
		return this.urlProcessor;
	}

	private String[] getStandAloneAppType() {
		String[] arrayOfString = { LocaleStrings.getString("S_38_SACD"), LocaleStrings.getString("S_39_SACD"),
				LocaleStrings.getString("S_27_SACD") };

		return arrayOfString;
	}

	private void resetDialogAndShowMessage(String paramString) {
		this.validate = false;
		enableDialog();
		this.ipText.setText(JViewer.getIp());
		this.unameText.setText(null);
		this.passwdText.setText(null);
		JOptionPane.showMessageDialog(getDialog(), paramString, LocaleStrings.getString("S_9_SACD"), 0);

		this.unameText.requestFocus();
	}

	public int restGetCSRFToken() {
		this.urlProcessor = new URLProcessor(null, 1);
		this.urlProcessor.setHostIP(this.hostIP);
		int i = this.urlProcessor.restProcessRequest("https://" + this.hostIP + ":" + this.secWebPort
				+ "/api/session?username=" + this.username + "&password=" + this.password);
		try {
			if (i == 0) {
				getProgressBar().setString(LocaleStrings.getString("S_48_SACD"));
				int j = -1;
				j = Integer.parseInt(this.urlProcessor.getValue("\"extendedpriv\": ", ','));
				JViewer.setKVMPrivilege(j);
				this.webSessionToken = this.urlProcessor.getValue("Set-Cookie: ", ';');
				JViewer.setWebSessionToken(this.webSessionToken);
				this.csrfToken = this.urlProcessor.getValue("\"CSRFToken\": ", ' ');
				this.csrfToken.trim();
				URLProcessor.setCsrfToken(this.csrfToken.substring(1, this.csrfToken.length() - 1));
				JViewer.setPassword(this.password);
			} else if (i == -6) {
				this.validate = false;
				enableDialog();
				this.ipText.setText(JViewer.getIp());
				this.unameText.setText(null);
				this.passwdText.setText(null);
				JOptionPane.showMessageDialog(getDialog(), LocaleStrings.getString("S_10_SACD"),
						JViewer.getTitle() + LocaleStrings.getString("S_9_SACD"), 0);

				this.unameText.requestFocus();
			} else if (i == -7) {
				this.windowListener.windowClosing(null);
			}
		} catch (Exception localException) {
			Debug.out.println(localException);
			showProgress(false);
			JOptionPane.showMessageDialog(getDialog(), LocaleStrings.getString("S_11_SACD"),
					LocaleStrings.getString("S_9_SACD"), 0);

			this.windowListener.windowClosing(null);
		}
		return i;
	}

	private void restGetVMediaConfig() {
		long l = 0L;
		this.urlProcessor = new URLProcessor(this.webSessionToken, 1);
		this.urlProcessor.setHostIP(this.hostIP);

		int j = this.urlProcessor
				.restProcessRequest("https://" + this.hostIP + ":" + this.secWebPort + "/api/settings/media/instance");

		if (j == 0) {
			try {
				getProgressBar().setString(LocaleStrings.getString("S_47_SACD"));
				String str = this.urlProcessor.getValue("\"single_port_enabled\": ", ',');

				if (1 == Integer.parseInt(str)) {
					JViewer.setSinglePortEnabled(true);
				} else {
					JViewer.setSinglePortEnabled(false);
				}
				str = this.urlProcessor.getValue("\"license\": ", ',');
				JViewer.setMediaLicenseStatus((byte) Integer.parseInt(str));
				if (!JViewer.isSinglePortEnabled()) {
					str = this.urlProcessor.getValue("\"secure_channel\": ", ',');
					int i = Integer.parseInt(str);
					JViewer.setVMSecureChannel(i);

					if (i == 0) {
						JViewer.setVMUseSSL(false);
						str = this.urlProcessor.getValue("\"cd_port\": ", ',');
						JViewer.setCdserver_port(Integer.parseInt(str));
						str = this.urlProcessor.getValue("\"fd_port\": ", ',');
						JViewer.setFdserver_port(Integer.parseInt(str));
						str = this.urlProcessor.getValue("\"hd_port\": ", ',');
						JViewer.setHdserver_port(Integer.parseInt(str));
					} else if (i == 1) {
						JViewer.setVMUseSSL(true);
						str = this.urlProcessor.getValue("\"cd_secure_port\": ", ',');
						JViewer.setCdserver_port(Integer.parseInt(str));
						str = this.urlProcessor.getValue("\"fd_secure_port\": ", ',');
						JViewer.setFdserver_port(Integer.parseInt(str));
						str = this.urlProcessor.getValue("\"hd_secure_port\": ", ',');
						JViewer.setHdserver_port(Integer.parseInt(str));
					}
				}

				try {
					l = Long.parseLong(this.urlProcessor.getValue("\"oemFeature\": ", ' '));
					JViewer.setOEMFeatureStatus(l);
				} catch (NumberFormatException localNumberFormatException1) {
					Debug.out.println(localNumberFormatException1);
					JOptionPane.showMessageDialog(this, LocaleStrings.getString("S_36_SACD"),
							LocaleStrings.getString("S_9_SACD"), 0);

					l = 0L;
				} catch (Exception localException) {
					Debug.out.println(localException);
					JOptionPane.showMessageDialog(this, LocaleStrings.getString("S_36_SACD"),
							LocaleStrings.getString("S_9_SACD"), 0);

					l = 0L;
				}

				str = this.urlProcessor.getValue("\"num_fd\": ", ',');
				JViewer.setNum_FD((byte) Integer.parseInt(str));

				str = this.urlProcessor.getValue("\"num_cd\": ", ',');
				JViewer.setNum_CD((byte) Integer.parseInt(str));

				str = this.urlProcessor.getValue("\"num_hd\": ", ',');
				JViewer.setNum_HD((byte) Integer.parseInt(str));

				str = this.urlProcessor.getValue("\"cd_status\": ", ',');
				JViewer.setCD_State(Integer.parseInt(str));
				str = this.urlProcessor.getValue("\"fd_status\": ", ',');
				JViewer.setFD_State(Integer.parseInt(str));
				str = this.urlProcessor.getValue("\"hd_status\": ", ',');
				JViewer.setHD_State(Integer.parseInt(str));

				str = this.urlProcessor.getValue("\"kvm_num_fd\": ", ',');
				JViewer.setKVM_Num_FD((byte) Integer.parseInt(str));

				str = this.urlProcessor.getValue("\"kvm_num_cd\": ", ',');
				JViewer.setKVM_Num_CD((byte) Integer.parseInt(str));

				str = this.urlProcessor.getValue("\"kvm_num_hd\": ", ',');
				JViewer.setKVM_Num_HD((byte) Integer.parseInt(str));
				str = this.urlProcessor.getValue("\"power_save_mode\": ", ',');
				if (str != null) {
					JViewer.setPowerSaveMode((byte) Integer.parseInt(str));
				} else {
					Debug.out.println("power_save_mode not found in the response data");
				}
			} catch (NumberFormatException localNumberFormatException2) {
				Debug.out.println(localNumberFormatException2);
				JOptionPane.showMessageDialog(this, LocaleStrings.getString("S_16_SACD"),
						LocaleStrings.getString("S_9_SACD"), 0);

				this.windowListener.windowClosing(null);
			} catch (NullPointerException localNullPointerException) {
				Debug.out.println(localNullPointerException);
				JOptionPane.showMessageDialog(this, LocaleStrings.getString("S_16_SACD"),
						LocaleStrings.getString("S_9_SACD"), 0);

				this.windowListener.windowClosing(null);
			}
		} else if (j == -1) {
			JOptionPane.showMessageDialog(this, LocaleStrings.getString("S_16_SACD"),
					LocaleStrings.getString("S_9_SACD"), 0);

			this.windowListener.windowClosing(null);
		} else if (j == -7) {
			this.windowListener.windowClosing(null);
		}
	}

	private void restGetAdviserConfig() {
		int n = 12;
		int i1 = 10;
		byte b = 0;
		String str = "AD";
		this.urlProcessor = new URLProcessor(this.webSessionToken, 1);
		this.urlProcessor.setHostIP(this.hostIP);
		try {
			int i2 = this.urlProcessor.restProcessRequest(
					"https://" + this.hostIP + ":" + this.secWebPort + "/api/settings/media/adviser");
			if (i2 == 0) {
				getProgressBar().setString(LocaleStrings.getString("S_46_SACD"));

				int i = Integer.parseInt(this.urlProcessor.getValue("\"status\": ", ','));
				if (i == 0) {
					JOptionPane.showMessageDialog(this, LocaleStrings.getString("S_14_SACD"),
							LocaleStrings.getString("S_9_SACD"), 0);

					this.windowListener.windowClosing(null);
				}
				int j = Integer.parseInt(this.urlProcessor.getValue("\"secure_channel\": ", ','));
				JViewer.setSecureChannel(j);

				int k = Integer.parseInt(this.urlProcessor.getValue("\"kvm_port\": ", ','));
				int m = Integer.parseInt(this.urlProcessor.getValue("\"web_port\": ", ','));

				if (JViewer.isSinglePortEnabled() == true) {

					JViewer.setKVMPort(m);

					JViewer.setUseSSL(true);
				} else {
					JViewer.setKVMPort(k);

					if (j == 0) {
						JViewer.setUseSSL(false);
					} else if (j == 1) {
						JViewer.setUseSSL(true);
					}
				}

				if ((JViewer.getOEMFeatureStatus() & 0x20) == 32L) {
					JViewer.setKVMReconnectEnabled(true);
					try {
						n = Integer.parseInt(this.urlProcessor.getValue("\"retry_count\": ", ','));
					} catch (NumberFormatException localNumberFormatException1) {
						Debug.out.println(localNumberFormatException1);
						JOptionPane.showMessageDialog(this, LocaleStrings.getString("S_40_SACD"),
								LocaleStrings.getString("S_9_SACD"), 0);
					} catch (Exception localException2) {
						Debug.out.println(localException2);
						JOptionPane.showMessageDialog(this, LocaleStrings.getString("S_40_SACD"),
								LocaleStrings.getString("S_9_SACD"), 0);
					}

					JViewer.setRetryCount(n);
					try {
						i1 = Integer.parseInt(this.urlProcessor.getValue("\"retry_interval\": ", ','));
					} catch (NumberFormatException localNumberFormatException2) {
						Debug.out.println(localNumberFormatException2);
						JOptionPane.showMessageDialog(this, LocaleStrings.getString("S_39_SACD"),
								LocaleStrings.getString("S_9_SACD"), 0);
					} catch (Exception localException3) {
						Debug.out.println(localException3);
						JOptionPane.showMessageDialog(this, LocaleStrings.getString("S_39_SACD"),
								LocaleStrings.getString("S_9_SACD"), 0);
					}

					JViewer.setRetryInterval(i1);
				}

				try {
					b = Byte.parseByte(this.urlProcessor.getValue("\"license\": ", ','));
					JViewer.setKVMLicenseStatus(b);
				} catch (NumberFormatException localNumberFormatException3) {
					Debug.out.print(localNumberFormatException3);
					JOptionPane.showMessageDialog(this, LocaleStrings.getString("S_37_SACD"),
							LocaleStrings.getString("S_9_SACD"), 0);

					JViewer.setKVMLicenseStatus((byte) 0);
				} catch (Exception localException4) {
					Debug.out.print(localException4);
					JOptionPane.showMessageDialog(this, LocaleStrings.getString("S_37_SACD"),
							LocaleStrings.getString("S_9_SACD"), 0);

					JViewer.setKVMLicenseStatus((byte) 0);
				}

				try {
					str = this.urlProcessor.getValue("\"keyboard_layout\": ", ' ');

					if ((str.startsWith("\"")) && (str.endsWith("\""))) {
						try {
							int i3 = str.indexOf('"') + 1;
							int i4 = str.lastIndexOf('"');
							str = str.substring(i3, i4);
						} catch (IndexOutOfBoundsException localIndexOutOfBoundsException) {
							Debug.out.println(localIndexOutOfBoundsException);
							str = "AD";
						} catch (Exception localException5) {
							Debug.out.println(localException5);
							str = "AD";
						}
					}
				} catch (Exception localException6) {
					Debug.out.println(localException6);
					str = "AD";
				}
				JViewer.setKeyboardLayout(str);

				JViewer.setKVM_Num_FD(JViewer.getKVM_Num_FD());
				JViewer.setKVM_Num_CD(JViewer.getKVM_Num_CD());
				JViewer.setKVM_Num_HD(JViewer.getKVM_Num_HD());
			} else if (i2 == -1) {
				JOptionPane.showMessageDialog(this, LocaleStrings.getString("S_15_SACD"),
						LocaleStrings.getString("S_9_SACD"), 0);

				this.windowListener.windowClosing(null);
			} else if (i2 == -7) {
				this.windowListener.windowClosing(null);
			}
		} catch (Exception localException1) {
			Debug.out.println(localException1);
			JOptionPane.showMessageDialog(this, LocaleStrings.getString("S_15_SACD"),
					LocaleStrings.getString("S_9_SACD"), 0);

			this.windowListener.windowClosing(null);
		}
	}

	private void restGetAdviserSessionToken() {
		String str = null;

		this.urlProcessor = new URLProcessor(this.webSessionToken, 1);
		this.urlProcessor.setHostIP(this.hostIP);
		int i = this.urlProcessor
				.restProcessRequest("https://" + this.hostIP + ":" + this.secWebPort + "/api/kvm/token");
		try {
			if (i == 0) {
				getProgressBar().setString(LocaleStrings.getString("S_49_SACD"));
				str = this.urlProcessor.getValue("\"token\": ", ',');
				JViewer.setSessionCookies(str.substring(1, str.length() - 1));

			} else if (i == -1) {
				showProgress(false);
				JOptionPane.showMessageDialog(this, LocaleStrings.getString("S_11_SACD"),
						LocaleStrings.getString("S_9_SACD"), 0);

				this.windowListener.windowClosing(null);
			} else if (i == -7) {
				this.windowListener.windowClosing(null);
			}
		} catch (Exception localException) {
			Debug.out.println(localException);
			showProgress(false);
			JOptionPane.showMessageDialog(this, LocaleStrings.getString("S_11_SACD"),
					LocaleStrings.getString("S_9_SACD"), 0);

			this.windowListener.windowClosing(null);
		}
	}

	public void setWebSessionToken(String paramString) {
		this.webSessionToken = paramString;
	}

	public static boolean isUnixFileClosed(File paramFile) {
		Process localProcess = null;
		BufferedReader localBufferedReader = null;
		try {
			localProcess = new ProcessBuilder(new String[] { "lsof", "|", "grep", paramFile.getAbsolutePath() })
					.start();
			localBufferedReader = new BufferedReader(new InputStreamReader(localProcess.getInputStream()));
			String str;
			while ((str = localBufferedReader.readLine()) != null) {
				if (str.contains(paramFile.getAbsolutePath())) {
					localBufferedReader.close();
					localProcess.destroy();
					return false;
				}
			}
		} catch (Exception localException) {
			Debug.out.println(localException);
			return false;
		}
		try {
			localBufferedReader.close();
		} catch (IOException localIOException) {
			Debug.out.println(localIOException);
		}
		localProcess.destroy();
		return true;
	}
}

/*
 * Location: D:\Users\tianlin\Downloads\JViewer.jar!\com\ami\kvm\jviewer\gui\
 * StandAloneConnectionDialog.class Java compiler version: 5 (49.0) JD-Core
 * Version: 0.7.1
 */